import time
from wordpress_project.base.base_page import Tools

class add_user_tool(Tools):
    """页面元素定位"""
    add_user_url = "http://192.168.0.125:9009/wp-admin/user-new.php"
    username_ele = '[name="user_login"]'
    email_ele = '[name="email"]'
    button_ele = '[id="createusersub"]'
    success_ele = '[id="message"]'
    fail_ele = '[class="error"]'

    def add_user_action(self,usr,email):
        self.log(f'正在进行添加用户操作，用户名为{usr},邮箱为{email}')
        # 在方法中，调用同一个类的其他方法，  self.方法名 , 在方法中，调用类的变量 self.变量名
        self.visit(self.add_user_url)
        self.by_css(self.username_ele).send_keys(usr)
        time.sleep(0.5)
        self.by_css(self.email_ele).send_keys(email)
        time.sleep(0.5)
        self.by_css(self.button_ele).click()
        time.sleep(1)
        self.img() # 调用截图


    def get_success_msg(self):
        return self.by_css(self.success_ele).text

    def get_fail_msg(self):
        return self.by_css(self.fail_ele).text






